import json
import unittest
import parameterized
import requests
from pythonProject3.api.ihrm_uermanage import emplyoee
from pythonProject3.tool.common import Commen_assert


def build_data():
    file="H:\\pythonProject3\\pythonProject3\\data\\addemp.json"
    test_data=[]
    with open(file,encoding="utf-8") as f:
        json_data=json.load(f)
        for test_case in json_data:
            username=test_case.get("username")
            mobile=test_case.get("mobile")
            workNumber=test_case.get("workNumber")
            success=test_case.get("success")
            code=test_case.get("code")
            message=test_case.get("message")
            test_data.append((username,mobile,workNumber,success,code,message))
        print(test_data)
    return test_data

class emp(unittest.TestCase):
    empid = None
    def setUp(self):
        self.session=requests.session()
        self.emp=emplyoee()


    def tearDown(self):
        if self.session:
            self.session.close()

    @parameterized.parameterized.expand(build_data())
    def test_1_add(self,username,mobile,workNumber,success,code,message):
        response=self.emp.emp_add(username,mobile,workNumber)
        print(response.json())

        Commen_assert(self,response,success,code,message)
        # global empid
        emp.empid=response.json().get("data").get("id")
        # return self.empid

    def test_2_update(self):
        data={
            "username":"susu967"
        }
        response=self.emp.emp_update(emp.empid,data)
        print(response.json())
        self.assertEqual("操作成功！", response.json().get("message"))

    def test_3_select(self):
        response=self.emp.emp_select(emp.empid)
        print(response.json())
        self.assertEqual(10000,response.json().get("code"))

    def test_4_del(self):
        response=self.emp.emp_del(emp.empid)
        print(response.json())
        self.assertEqual(10000, response.json().get("code"))